﻿/// <reference Path="jquery-1.3.2-vsdoc.js" />
// 常用方法
var $t = {
    event: function() { // 取得 event 对象
        if (document.all) { return window.event; }
        var func = this.event.caller;
        while (func != null) {
            var arg0 = func.arguments[0];
            if (arg0 instanceof Event) { return arg0; }
            func = func.caller;
        }
        return null;
    },
    stopPropagation: function() { // 停止事件冒泡
        var event = this.event();
        if (event) {
            if (event.stopPropagation) event.stopPropagation();
            else event.cancelBubble = true;
        }
    },
    preventDefault: function() { // 取消默认行为
        var event = this.event();
        if (event) {
            if (event.preventDefault) event.preventDefault();
            else event.returnValue = false;
        }
    },
    pos: function(o) { // 获取对象的绝对位置
        if (arguments.length != 1 || o == null) return null;
        var t = o.offsetTop, l = o.offsetLeft;
        var w = o.offsetWidth, h = o.offsetHeight;
        while (o = o.offsetParent) {
            t += o.offsetTop;
            l += o.offsetLeft;
        }
        return { AbsoluteTop: t, AbsoluteLeft: l, OffsetWidth: w, OffsetHeight: h };
    }
};
// 每个页都调用脚本
var $c = {
    auto: function() { // 布局自适应
        var top = $("#div-top"), middle = $("#div-middle"), bottom = $("#div-bottom");
        middle.height($(window).height() - bottom.height() - top.height());
    },
    go: function(action, info) { // url 跳转或执行指定的 js 方法
        var flag = true;
        if (info) { flag = window.confirm(info); }
        if (flag) {
            if (typeof action === "function") {
                eval(action).call();
            } else { window.location.assign(action); }
        }
        $t.stopPropagation();
    },
    trClick: function() { // 单击选择行
        $(":checkbox[name='cbKey']").click(function() {
            $(this).attr("checked", !$(this).attr("checked"));
        });
        var c = "#CAD9EA";
        $("tr[char='tr']").click(function() {
            var cb = $(this).find(":checkbox[name='cbKey']");
            cb.attr("checked", !cb.attr("checked"));
            if ($(this).find(":checkbox[name='cbKey']").attr("checked")) {
                $(this).unbind("mouseover").unbind("mouseout").css("background-color", c);
            } else {
                $(this).bind("mouseover", function() {
                    $(this).css({ backgroundColor: c, cursor: "pointer" });
                }).bind("mouseout", function() {
                    $(this).css({ backgroundColor: "", cursor: "default" });
                });
            }
        }).bind("mouseover", function() {
            $(this).css({ backgroundColor: c, cursor: "pointer" });
        }).bind("mouseout", function() {
            $(this).css({ backgroundColor: "", cursor: "default" });
        });
        $t.stopPropagation();
    },
    inputRequired: function(jqElm, info) {
        if (jqElm.val() == "") {
            alert(info);
            jqElm.focus().addClass("in-error")
                .blur(function() { if ($(this).val() != "") { $(this).removeClass("in-error"); } });
            return false;
        }
        return true;
    }
};